#include <everest/dbc/odbc/odbc_common.h>
#include <vector>
#include <string.h>
#include <stdio.h>

using namespace NS_EVEREST::dbc::odbc;
using namespace NS_EVEREST::dbc;
using namespace NS_EVEREST;
using namespace std;

bool everest::dbc::odbc::OdbcColDesc::transToCType(OdbcColDesc *pDesc)
{
	bool result = true;
	switch (pDesc->datatype) {
	case SQL_CHAR:
	case SQL_VARCHAR:
	case SQL_LONGVARCHAR:
		pDesc->targettype = SQL_C_CHAR;
		pDesc->targetsize = pDesc->colsize;
		break;
	case SQL_WCHAR:
	case SQL_WVARCHAR:
	case SQL_WLONGVARCHAR:
		pDesc->targettype = SQL_C_CHAR;
		pDesc->targetsize = pDesc->colsize * 2;
		break;
	case SQL_BIT:
	case SQL_TINYINT:
	case SQL_SMALLINT:
	case SQL_INTEGER:
		pDesc->targettype = SQL_C_SLONG;
		pDesc->targetsize = sizeof(int);
		break;
	case SQL_BIGINT:
		pDesc->targettype = SQL_C_SBIGINT;
		pDesc->targetsize = sizeof(SQLBIGINT);
		break;
	case SQL_REAL:
		pDesc->targettype = SQL_C_FLOAT;
		pDesc->targetsize = sizeof(float);
		break;
	case SQL_FLOAT:
	case SQL_DOUBLE:
		pDesc->targettype = SQL_C_DOUBLE;
		pDesc->targetsize = sizeof(double);
		break;
	case SQL_DECIMAL:
	case SQL_NUMERIC:
		pDesc->targettype = SQL_C_NUMERIC;
		pDesc->targetsize = sizeof(SQL_NUMERIC_STRUCT);
		break;
	case SQL_BINARY:
	case SQL_VARBINARY:
	case SQL_LONGVARBINARY:
		pDesc->targettype = SQL_C_BINARY;
		pDesc->targetsize = pDesc->colsize;
		break;
	case SQL_TYPE_DATE:
	case SQL_TYPE_TIME:
	case SQL_TYPE_TIMESTAMP:
		pDesc->targettype = SQL_C_TYPE_TIMESTAMP;
		pDesc->targetsize = sizeof(TIMESTAMP_STRUCT);
		break;
	case SQL_GUID:
		pDesc->targettype = SQL_C_CHAR;
		pDesc->targetsize = 37;
		break;
	case SQL_INTERVAL_YEAR:
	case SQL_INTERVAL_MONTH:
	case SQL_INTERVAL_YEAR_TO_MONTH:
	case SQL_INTERVAL_DAY:
	case SQL_INTERVAL_DAY_TO_MINUTE:
	case SQL_INTERVAL_HOUR:
	case SQL_INTERVAL_DAY_TO_SECOND:
	case SQL_INTERVAL_MINUTE:
	case SQL_INTERVAL_HOUR_TO_MINUTE:
	case SQL_INTERVAL_SECOND:
	case SQL_INTERVAL_HOUR_TO_SECOND:
	case SQL_INTERVAL_DAY_TO_HOUR:
	case SQL_INTERVAL_MINUTE_TO_SECOND:
		pDesc->targettype = SQL_C_CHAR;
		pDesc->targetsize = 32;
		break;
	default:
		pDesc->targettype = SQL_C_CHAR;
		pDesc->targetsize = 64;
		break;
	} // end of switch
	return result;
} // end of OdbcTransToCType()

